import Vue from 'vue'
import Router from 'vue-router'
import getters from '@/store/getters'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/centre',
  //   component: () => import('@/views/centre/index'),
  //   hidden: true
  // },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/centre',
    component: Layout,
    redirect: '/centre',
    children: [{
      path: 'centre',
      name: 'Centre',
      component: () => import('@/views/centre/index'),
      meta: { title: '个人中心', icon: 'el-icon-s-home' }
    }]
  },


  // {
  //   path: '/genre',
  //   component: Layout,
  //   redirect: '/centre',
  //   children: [{
  //     path: 'centre',
  //     name: 'centre',
  //     component: () => import('@/views/centre/index'),
  //     meta: { title: '个人中心', icon: 'el-icon-s-home' }
  //   }]
  // },

  {
    path: '/healthAssessment',
    component: Layout,
    hidden: true,
    redirect: '/healthAssessment/physiqueEvaluation',
    name: '健康评估',
    meta: { title: '健康评估', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'healthAssessment/physiqueEvaluation',
        name: 'PhysiqueEvaluation',
        component: () => import('@/views/healthAssessment/physiqueEvaluation/physiqueEvaluation.vue'),
        meta: { title: '体质测评' }
      },
      {
        path: 'healthAssessment/psychologicalEvaluation',
        name: 'PhycologicalEvaluation',
        component: () => import('@/views/healthAssessment/psychologicalEvaluation/psychologicalEvaluation.vue'),
        meta: { title: '心理测评' }
      },
      {
        path: 'healthAssessment/riskAssessment',
        name: 'RiskAssessment',
        component: () => import('@/views/healthAssessment/riskAssessment/riskAssessment.vue'),
        meta: { title: '风险评估' }
      }
    ]
  },
  {
    path: '/health/listener',
    component: Layout,
    redirect: 'listener',
    name: 'health',
    hidden: true,
    meta: { title: '健康干预', icon: 'el-icon-hot-water' },
    children: [
      {
        path: 'listener',
        name: 'Listener',
        component: () => import('@/views/health intervention/listener'),
        meta: { title: '人群分类', icon: 'el-icon-s-custom' }
      },
      {
        path: 'healthscheme',
        name: 'Healthscheme',
        component: () => import('@/views/health intervention/healthscheme'),
        meta: { title: '干预方案', icon: 'el-icon-edit-outline' }
      },
      {
        path: 'diary',
        name: 'Diary',
        component: () => import('@/views/health intervention/diary'),
        meta: { title: '随访日记', icon: 'el-icon-notebook-1' }
      },
      {
        path: 'target',
        name: 'Target',
        component: () => import('@/views/health intervention/target'),
        meta: { title: '指标管理', icon: 'el-icon-pie-chart' }
      },
      {
        path: 'template',
        name: 'Template',
        component: () => import('@/views/health intervention/masterplate.vue'),
        meta: { title: '模版管理', icon: 'tree' }
      }
    ]
  },
  {
    path: '/system/manage',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/user.vue')
      },
      {
        path: 'jsgl',
        name: 'Jsgl',
        component: () => import('@/views/xtsz/jsgl'),
        meta: { title: '角色管理', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    path: '/member/listener',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'member',
        name: 'member',
        component: () => import('@/views/member/listener')
      },
      {
        path: 'upload',
        name: 'upload',
        component: () => import('@/views/member/upload')
      },
      {
        path: 'statistics',
        name: 'statistics',
        component: () => import('@/views/member/statistics.vue')
      }
    ]
  },
  {
    path: '/zsk',
    component: Layout,
    name: 'Zsk',
    hidden: true,
    meta: { title: '知识库', icon: 'el-icon-collection' },
    children: [
      {
        path: 'pgjy',
        name: 'Pgjy',
        component: () => import('@/views/zsk/pgjy'),
        meta: { title: '评估建议', icon: 'el-icon-s-custom' }
      },
      {
        path: 'jkfa',
        name: 'Jkfa',
        component: () => import('@/views/zsk/jkfa'),
        meta: { title: '健康方案', icon: 'el-icon-document' }
      },
      {
        path: 'ydxm',
        name: 'Ydxm',
        component: () => import('@/views/zsk/ydxm'),
        meta: { title: '运动项目', icon: 'el-icon-bicycle' }
      },
      {
        path: 'ssk',
        name: 'Ssk',
        component: () => import('@/views/zsk/ssk'),
        meta: { title: '膳食库', icon: 'el-icon-fork-spoon' }
      },
      {
        path: 'jbk',
        name: 'Jbk',
        component: () => import('@/views/zsk/jbk'),
        meta: { title: '疾病库', icon: 'el-icon-eleme' }
      }
    ]
  },
  {
    path: '/xtsz',
    component: Layout,
    name: 'Xtsz',
    hidden: true,
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'gy',
        name: 'gy',
        // component: () => import('@/views/zsk/gy'),
        meta: { title: '方案', icon: 'el-icon-user-solid' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
